//=============================================
void my_comtrade_send_message(comtrade *data)
{
    char str[10]= {'\0'};
	char _str[32752]={'\0'};//32768-17+1=32752,32752/4=8938
	//memset(_str,0,32752);
	int buf_len=0;
	int i=0,j=0;
    sprintf(str,"%d",data->flag);
    strcat(_str,str);
    strcat(_str,",");//字符串连接
    sprintf(str,"%d",data->len);
    strcat(_str,str);
    strcat(_str,",");//字符串连接

	printf("size = %d\r\n",sizeof(comtrade));
	 //---------------------------发送U
	for(i=0,j=0;i<8;j++)
	{
        if(j==1200)
		{
			j=0;
			i++;
			if(i==8)
			{
				break;
			}
		}
		sprintf(str,"%d",data->U[i][j]);
		if((strlen(_str)+strlen(str))<32751)
		{
			strcat(_str,str);
			strcat(_str,",");//字符串连接
		}
		else
		{
			  uint32_t time_start = HAL_GetTick();
			  if(OPENAMP_send(&resmgr_ept, _str, strlen(_str)) < 0)
			  {
				  printf("Failed to send message size=%d\r\n",strlen(_str));
				  Error_Handler();
			  }
			  else
			  {
				  uint32_t time_end = HAL_GetTick();
				  printf("time_end - time_start =%ld\r\n",time_end - time_start);
				  printf("M4 send_rpmsg= ok size =%d\r\n",strlen(_str));
			  }
			  buf_len+=strlen(_str);
			  memset(_str,0,32752);
			  strcat(_str,str);
			  strcat(_str,",");//字符串连接
		}
    }
    strcat(_str,"U");//u结束
    if(OPENAMP_send(&resmgr_ept, _str, strlen(_str)) < 0)
    {
	    printf("Failed to send message size=%d\r\n",strlen(_str));
	     Error_Handler();
    }
    else
	     printf("M4 send_rpmsg= ok size =%d\r\n",strlen(_str));
    buf_len+=strlen(_str);
    memset(_str,0,32752);//字符数组清0
  //------------------------------------发送I
    for(i=0,j=0;i<36;j++)
    {
        if(j==1200)
	    {
	        j=0;
		    i++;
		    if(i==36)
		    {
		        break;
		    }
        }
        sprintf(str,"%d",data->I[i][j]);
	    if((strlen(_str)+strlen(str))<32751)
	    {
	        strcat(_str,str);
		    strcat(_str,",");//字符串连接
	    }
	    else
	    {
		      if(OPENAMP_send(&resmgr_ept, _str, strlen(_str)) < 0)
		      {
			      printf("Failed to send message size=%d\r\n",strlen(_str));
			      Error_Handler();
		      }
		      else
			      printf("M4 send_rpmsg= ok size =%d\r\n",strlen(_str));
		      buf_len+=strlen(_str);
		      memset(_str,0,32752);
		      strcat(_str,str);
		      strcat(_str,",");//字符串连接
	    }


	}
	  strcat(_str,"I");//I结束
	  if(OPENAMP_send(&resmgr_ept, _str, strlen(_str)) < 0)
	  {
		  printf("Failed to send message size=%d\r\n",strlen(_str));
		  Error_Handler();
	  }
	  else
		  printf("M4 send_rpmsg= ok size =%d\r\n",strlen(_str));
	  buf_len+=strlen(_str);
	  memset(_str,0,32752);
	  strcat(_str,"off");
	  printf("_str off=%s\r\n",_str);
	  if(OPENAMP_send(&resmgr_ept, _str, strlen(_str)) < 0)
	  {
		  printf("Failed to send message size=%d\r\n",strlen(_str));
		  Error_Handler();
	  }
	  else
		  printf("M4 send_rpmsg= ok size =%d\r\n",strlen(_str));
	  printf("Over\r\n");
}


//-------------------

typedef struct
{
	uint16_t flag;
	uint16_t len;
	uint16_t U[8][1200];
	uint16_t I[36][1200];
}comtrade;
//---------------------
void data_init(comtrade *data)
{

	data->flag = 1;
	data->len = sizeof(comtrade);
	int Am = 1000;

	for(int i=0;i<8;i++)
	{
		for(int j=0;j<1200;j++)
		{
			data->U[i][j] = Am*sin(2*6.28/120);
		}
		Am = 2*Am;
	}
	Am = 1000;
	for(int i=0;i<36;i++)
	{
		for(int j=0;j<1200;j++)
		{
			data->I[i][j] = Am*sin(2*6.28/120);
		}
		Am = Am+2000;
	}
}
//-----------------------------------------